import { getEntireRoles, getEntireDeparments, getEntireMenu } from '@/service/main/main'
import { defineStore } from 'pinia'

import type { roleList, departmentList, menuList } from '@/types/main'

interface IMainStateType {
  entireRole: roleList[]
  entireDepartment: departmentList[]
  entireMenu: menuList[]
}

const useMainStore = defineStore('main', {
  state: (): IMainStateType => ({
    entireRole: [],
    entireDepartment: [],
    entireMenu: []
  }),
  actions: {
    async fetchEntireDataAction() {
      const rolesResult = await getEntireRoles()
      const departmentResult = await getEntireDeparments()
      const menuResult = await getEntireMenu()

      this.entireRole = rolesResult.data.list
      this.entireDepartment = departmentResult.data.list
      this.entireMenu = menuResult.data.list
    }
  }
})

export default useMainStore
